/*
 * Copyright (c) 2022, IMMORTA Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * - Neither the name of IMMORTA Inc. nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef ERRCODES_H
#define ERRCODES_H

/*!
 * @file errcodes.h
 * @brief This file provide API return error codes
 */

/*******Includes***************************************************************/


/*******Definitions************************************************************/
/*!
 * @brief Status return codes,
 *        Common error codes will be a unified enumeration (C enum) that will contain all error codes
 *        (common and specific)
 */
typedef enum {
    /********************* Generic error codes *******************************/
    ERR_SUCCESS                         = 0x000U,    /*!< Generic operation success ERR */
    ERR_ERROR                           = 0x001U,    /*!< Generic operation failure ERR */
    ERR_BUSY                            = 0x002U,    /*!< Generic operation busy ERR */
    ERR_TIMEOUT                         = 0x003U,    /*!< Generic operation timeout ERR */
    ERR_UNSUPPORTED                     = 0x004U,    /*!< Generic operation unsupported ERR */

    /********************* I2C specific error codes *************************/
    ERR_I2C_RECEIVED_NACK               = 0x100U,    /*!< NACK signal received */
    ERR_I2C_TX_UNDERRUN                 = 0x101U,    /*!< TX underrun error */
    ERR_I2C_RX_OVERRUN                  = 0x102U,    /*!< RX overrun error */
    ERR_I2C_ARBITRATION_LOST            = 0x103U,    /*!< Arbitration lost */
    ERR_I2C_ABORTED                     = 0x104U,    /*!< A transfer was aborted */
    ERR_I2C_BUS_BUSY                    = 0x105U,    /*!< I2C bus is busy, cannot start transfer */
    ERR_I2C_BUS_LOW_TIMEOUT             = 0x106U,    /*!< I2C bus low timeout is detected */

    /********************* UART specific error codes *************************/
    ERR_UART_RX_OVERRUN                 = 0x201U,    /*!< RX overrun error */
    ERR_UART_ABORTED                    = 0x202U,    /*!< A transfer was aborted */
    ERR_UART_FRAMING_ERROR              = 0x203U,    /*!< Framing error */
    ERR_UART_PARITY_ERROR               = 0x204U,    /*!< Parity error */
    ERR_UART_NOISE_ERROR                = 0x205U,    /*!< Noise error */

    /********************* RTC specific error codes *************************/
    ERR_RTC_ALREADY_RUNNING             = 0x301U,    /*!< RTC is running  */
    ERR_RTC_INVALID_STATE               = 0x302U,    /*!< Invalid state  */
    ERR_RTC_WRONG_TIMEDATE              = 0x303U,    /*!< Time or date is error  */
    ERR_RTC_CLOCK_DOMAIN_SYNC_ERROR     = 0x304U,    /*!< RTC and Bus clock domain sync error  */
    ERR_RTC_INVALID_COMP_RANGE          = 0x305U,    /*!< Compensation is out of range */

    /********************* SPI specific error codes *************************/
    ERR_SPI_TX_UNDERRUN                 = 0x401U,    /*!< TX underflow error */
    ERR_SPI_RX_OVERFLOW                 = 0x402U,    /*!< RX overflow error */
    ERR_SPI_ABORTED                     = 0x403U,    /*!< A transfer was aborted */

    /********************* FLASH specific error codes *************************/
    ERR_FLASH_PARAMETER_ERROR           = 0x501U,    /*!< Flash input parameter error */
    ERR_FLASH_READ_PROTECTION_ERROR     = 0x502U,    /*!< Flash read protection violation */
    ERR_FLASH_WRITE_PROTECTION_ERROR    = 0x503U,    /*!< Flash write protection violation */
    ERR_FLASH_OPTION_BYTE_ERROR         = 0x504U,    /*!< Flash option byte error */

    /********************* CAN specific error codes *************************/
    ERR_CAN_RXFIFO_EMPTY                = 0x601U,    /*!< Receive buffer is empty */
    ERR_CAN_TX_IDLE                     = 0x602U,    /*!< Transmit buffer is idle */
    ERR_CAN_TX_BUSY                     = 0x603U,    /*!< Transmit buffer is busy */

    /********************* HSM specific error codes *************************/
    ERR_HSM_KEY_EMPTY                   = 0x701U,    /*!< Attempt to use a key that has not been initialized yet or crc error */
    ERR_HSM_KEY_UPDATE_ERROR            = 0x702U,    /*!< Key update did not succeed due to errors in verification of the messages */
    ERR_HSM_KEY_LEN_ERROR               = 0x703U,    /*!< Key length error */
    ERR_HSM_KEY_WRITE_PROTECTED         = 0x704U,    /*!< Request for updating a write protected key slot with write protected key(s) */
    ERR_HSM_KEY_BOOT_PROTECTED          = 0x705U,    /*!< A key is locked due to failed boot measurement */
    ERR_HSM_KEY_USAGE                   = 0x706U,    /*!< A key is only use for cmac general and verify */
    ERR_HSM_KEY_VERIFY_ONLY             = 0x707U,    /*!< A key is only use for cmac verify */
    ERR_HSM_KEY_INVALID                 = 0x708U,    /*!< A function is called to perform an operation with a key that is not allowed for the given operation */
    ERR_HSM_KEY_NOT_AVAILABLE           = 0x709U,    /*!< A key is locked due to failed boot measurement or an active debugger */
    ERR_HSM_DATA_LENGTH_ERROR           = 0x70AU,    /*!< The data or message length is not a multiple of the algorithm length */
    ERR_HSM_ALG_TYPE_ERROR              = 0x70BU,    /*!< Wrong algorithm type */
    ERR_HSM_CRPTO_ERROR                 = 0x70CU,    /*!< encrypt,decrypt and mac function execute error */
    ERR_HSM_NO_SECURE_BOOT              = 0x70DU,    /*!< The conditions for a secure boot process are not met */
    ERR_HSM_BOOT_TYPE_ERROR             = 0x70EU,    /*!< Wrong boot type */
    ERR_HSM_SEQUENCE_ERROR              = 0x70FU,    /*!< The sequence of commands or subcommands is out of sequence */
    ERR_HSM_LIFE_CYCLE_TYPE_ERROR       = 0x710U,    /*!< Life cycle type error */
    ERR_HSM_LIFECYCLE_LIMIT             = 0x711U,    /*!< Lifecycle limit */
    ERR_HSM_CHALLENGE_INVALID           = 0x712U,    /*!< Invalid challenge */
    ERR_HSM_AUTH_TYPE_ERROR             = 0x713U,    /*!< Invalid challenge */
    ERR_HSM_MEMORY_FAILURE              = 0x714U,    /*!< General memory technology failure(multibit ECC error, common fault detected) */
    ERR_HSM_CMD_ID_ERROR                = 0x715U,    /*!< Mailbox command id error */
    ERR_HSM_CMD_INVALID_ARG             = 0x716U     /*!< Invalid command argument */

} errcode_t;

#endif /* ERRCODES_H */

/*******EOF********************************************************************/
